using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using AFI.Speargun.Web.Models;
using AFI.Speargun.Web.Models.Validation;
using AFI.Speargun.Web.Core;

namespace AFI.Speargun.Web.Controllers
{
    public class AssetEntryAdditionalController : BaseController
    {
        //
        // GET: /AssetEntryAdditional/Details/{id}

        [Authorize]
        public ActionResult Details(Guid id)
        {
            var assetEntry = _service.GetAssetEntry(id);

            ViewData["AssetEntry.Appellation"] = assetEntry.Appellation;
            ViewData["AssetEntryId"] = id;

            return View(_service.GetAssetEntryAdditional(id));
        }

        //
        // GET: /AssetEntryAdditional/Edit/{id}

        [Authorize]
        public ActionResult Edit(Guid id)
        {
            var assetEntry = _service.GetAssetEntry(id);

            ViewData["AssetEntry.Appellation"] = assetEntry.Appellation;
            ViewData["AssetEntryId"] = id;

            return View(_service.GetAssetEntryAdditional(id));
        }

        //
        // POST: /AssetEntryAdditional/Edit/{id}

        [AcceptVerbs(HttpVerbs.Post)]
        [Authorize]
        public ActionResult Edit(Guid id, AssetEntryAdditional assetEntryAdditional)
        {
            var assetEntry = _service.GetAssetEntry(id);

            assetEntryAdditional.AssetEntryId = id;

            if (_service.EditAssetEntryAdditional(assetEntryAdditional))
                return RedirectToAction("Details", new { id = id });

            ViewData["AssetEntry.Appellation"] = assetEntry.Appellation;
            ViewData["AssetEntryId"] = id;

            return View(_service.GetAssetEntryAdditional(id));
        }
    }
}
